package com.realgodo.site.web.user.show.comment;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.communication.Comment;
import com.realgodo.site.service.communication.CommentManager;
import com.realgodo.site.web.user.UserDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/user/show/comment/?aid=${aid}") })
public class IndexController extends UserDefaultController {

	private static final long serialVersionUID = 6119813302145823698L;

	/**
	 * Application.id
	 */
	private Long aid;
	@Autowired
	private CommentManager commentManager;

	private Page<Comment> commentPage = new Page<Comment>(10);

	public String execute() {
		commentPage.setPageNo(commentManager.isParamNotNull(getParamMap(),
				Page.PAGE) ? Integer.valueOf((String) commentManager
				.getParamValue(getParamMap(), Page.PAGE)) : 1);// 查询页数
		this.commentPage = commentManager.findComments(commentPage, getAid());
		super.setPageInfo(commentPage);

		return SUCCESS;
	}

	public String remove() {
		if (getId() != null) {
			this.commentManager.delete(getId());
		}
		return "toindex";
	}

	/**************** getter and setter *******************/
	public Page<Comment> getCommentPage() {
		return commentPage;
	}

	public void setCommentPage(Page<Comment> commentPage) {
		this.commentPage = commentPage;
	}

	public Long getAid() {
		return aid;
	}

	public void setAid(Long aid) {
		this.aid = aid;
	}

}
